package com.itheima.utils;

import com.itheima.pojo.Habitus;
import com.itheima.pojo.Question;
import java.util.List;


public class HabitusUtils {

    public static List<Habitus> compute(List<Habitus> habituses){
        for (Habitus habitus : habituses) {
            //平和质算法特殊
           if(habitus.getId()==9){
             continue;
           }else {
               int sun=0;
               int count=habitus.getQuestions().size();
               for (Question question : habitus.getQuestions()) {
                   sun +=question.getScore();
               }
               int value=((sun-count)/(count*4))*100;
               if (value>=40){
                   habitus.setStatus(2);
               }else if(value<30){
                   habitus.setStatus(0);
               }else {
                   habitus.setStatus(1);
               }
           }
        }
        habituses =computeNine(habituses);

        return habituses;
    }

    private static List<Habitus> computeNine(List<Habitus> habituses) {
        for (Habitus habitus : habituses) {
            if (habitus.getId() == 9) {
                int sun = 0;
                int count = habitus.getQuestions().size();
                for (Question question : habitus.getQuestions()) {
                    if(question.getId()==133){
                        sun+=question.getScore();
                    }
                    sun += (6 - question.getScore());
                }
                int value = ((sun - count) / (count * 4)) * 100;

                int status = 2;

                if (value >= 60) {
                    for (Habitus habitus1 : habituses) {
                        if (habitus.getStatus() == 2) {
                            status = 0;
                            break;
                        }
                        if (habitus1.getStatus() == 1) {
                            status = 1;
                        }
                    }
                } else {
                    status = 0;
                }
                habitus.setStatus(status);
            }
        }
        return habituses;
    }
}
